package primary.design;

import java.util.Stack;

/*
    抄抄官方题解，没想出来
 */
class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> stackMin;
    public MinStack() {
        stack = new Stack<>();
        stackMin = new Stack<>();
    }

    public void push(int val) {
        if(stack.empty()){
            stack.push(val);
            stackMin.push(val);
        }else{
            stack.push(val);
            int min = stackMin.peek() < val ? stackMin.peek() : val;
            stackMin.push(min);

        }
    }

    public void pop() {
        stack.pop();
        stackMin.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return stackMin.peek();
    }
}
/**
 * @Author Elephas
 * @Date 2022/1/9
 **/

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack obj = new MinStack();
 * obj.push(val);
 * obj.pop();
 * int param_3 = obj.top();
 * int param_4 = obj.getMin();
 */